#include <iostream>

using namespace std;

struct B {};
struct D1 : public B{};
struct D2 : public D1{};

template <class I>
void func(I& p, B)
{
    cout << "B version" << endl;
}

template <class I>
void func(I& p, D2)
{
    cout << "D2 version" << endl;
}

int main(int argc, char** argv) 
{
    int* p;
    func(p, B());   // "B version"
    func(p, D1());  // "B version"
    func(p, D2());  // "D2 version"
    return 0;
}